<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户信息 - 志愿服务管理系统</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.1.3/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        :root {
            --primary-color: #2c3e50;
            --secondary-color: #34495e;
            --accent-color: #3498db;
            --danger-color: #e74c3c;
            --success-color: #2ecc71;
            --text-light: #ecf0f1;
            --text-dark: #2c3e50;
            --bg-light: #f8f9fa;
            --border-radius: 8px;
            --box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }

        body {
            background-color: #f5f6fa;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            color: var(--text-dark);
            min-height: 100vh;
            padding: 2rem;
        }

        .main-container {
            max-width: 1200px;
            margin: 0 auto;
            animation: fadeIn 0.5s ease;
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(-20px); }
            to { opacity: 1; transform: translateY(0); }
        }

        .card {
            background: white;
            border-radius: var(--border-radius);
            box-shadow: var(--box-shadow);
            border: none;
            margin-bottom: 2rem;
        }

        .card-header {
            background: var(--primary-color);
            color: white;
            border-radius: var(--border-radius) var(--border-radius) 0 0;
            padding: 1.5rem;
            position: relative;
        }

        .card-title {
            margin: 0;
            font-size: 1.5rem;
            font-weight: 500;
            text-align: center;
        }

        .table-responsive {
            padding: 1rem;
        }

        .table {
            width: 100%;
            margin-bottom: 0;
        }

        .table th {
            background-color: var(--bg-light);
            color: var(--secondary-color);
            font-weight: 600;
            border: none;
            padding: 1rem;
        }

        .table td {
            padding: 1rem;
            vertical-align: middle;
            border-color: #eee;
        }

        .table tbody tr {
            transition: all 0.3s ease;
        }

        .table tbody tr:hover {
            background-color: rgba(52, 152, 219, 0.05);
        }

        .table .actions {
            display: flex;
            gap: 0.5rem;
            justify-content: flex-start;
        }

        .btn {
            padding: 0.5rem 1rem;
            border: none;
            border-radius: var(--border-radius);
            font-weight: 500;
            transition: all 0.3s ease;
        }

        .btn-edit {
            background-color: var(--accent-color);
            color: white;
        }

        .btn-delete {
            background-color: var(--danger-color);
            color: white;
        }

        .btn:hover {
            transform: translateY(-1px);
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
        }

        .btn-back {
            position: absolute;
            top: 1rem;
            right: 1rem;
            color: var(--text-light);
            text-decoration: none;
            transition: all 0.3s ease;
        }

        .btn-back:hover {
            color: white;
            transform: translateX(-3px);
        }

        .pagination {
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 0.5rem;
            margin: 2rem 0;
        }

        .pagination a {
            padding: 0.5rem 1rem;
            background-color: white;
            color: var(--secondary-color);
            border-radius: var(--border-radius);
            text-decoration: none;
            transition: all 0.3s ease;
        }

        .pagination a.active {
            background-color: var(--accent-color);
            color: white;
        }

        .pagination a:hover:not(.active) {
            background-color: var(--bg-light);
            transform: translateY(-1px);
        }

        .page-info {
            text-align: center;
            color: var(--secondary-color);
            margin-top: 1rem;
        }

        .password-cell {
            font-family: monospace;
            letter-spacing: 1px;
        }

        @media (max-width: 768px) {
            body {
                padding: 1rem;
            }

            .table-responsive {
                padding: 0.5rem;
            }

            .btn {
                padding: 0.4rem 0.8rem;
                font-size: 0.9rem;
            }

            .pagination {
                flex-wrap: wrap;
            }
        }
    </style>
</head>
<body>
    <div class="main-container">
        <div class="card">
            <div class="card-header">
                <h2 class="card-title">
                    <i class="fas fa-users me-2"></i>用户列表
                </h2>
                <a class="btn-back" th:href="@{/toSuperAdminPage}">
                    <i class="fas fa-times"></i>
                </a>
            </div>
            <div class="table-responsive">
                <table class="table">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>昵称</th>
                            <th>账号</th>
                            <th>密码</th>
                            <th>志愿时长</th>
                            <th>注册时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr th:each="user : ${users}">
                            <td th:text="${user.getId()}"></td>
                            <td th:text="${user.getNickname()}"></td>
                            <td th:text="${user.getMobile()}"></td>
                            <td class="password-cell">
                                <span>••••••••</span>
                            </td>
                            <td th:text="${user.getTotalVolunteerHours()}"></td>
                            <td th:text="${user.getRegisterDate()}"></td>
                            <td class="actions">
                                <a class="btn btn-edit" th:href="@{'/updateUserPage/'+${user.getId()}}">
                                    <i class="fas fa-edit"></i>
                                </a>
                                <a class="btn btn-delete" th:href="@{'/deleteUser/'+${user.getId()}}" 
                                   onclick="return confirm('确定要删除这个用户吗？');">
                                    <i class="fas fa-trash"></i>
                                </a>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>

        <div class="pagination" th:if="${totalPages > 1}">
            <a th:if="${currentPage > 1}" th:href="@{/userList(currentPage=1)}">
                <i class="fas fa-angle-double-left"></i>
            </a>
            <a th:if="${currentPage > 1}" th:href="@{/userList(currentPage=${currentPage - 1})}">
                <i class="fas fa-angle-left"></i>
            </a>

            <a th:if="${totalPages > 1}" th:href="@{/userList(currentPage=1)}" 
               th:class="${currentPage == 1} ? 'active' : ''">1</a>
            <a th:if="${totalPages > 2}" th:href="@{/userList(currentPage=2)}" 
               th:class="${currentPage == 2} ? 'active' : ''">2</a>

            <span th:if="${totalPages > 4 && currentPage > 3}">...</span>

            <a th:if="${currentPage > 2 && currentPage < totalPages - 1}" 
               th:href="@{/userList(currentPage=${currentPage})}" 
               class="active" th:text="${currentPage}"></a>

            <span th:if="${totalPages > 4 && currentPage < totalPages - 2}">...</span>

            <a th:if="${totalPages > 3}" th:href="@{/userList(currentPage=${totalPages - 1})}" 
               th:class="${currentPage == totalPages - 1} ? 'active' : ''" 
               th:text="${totalPages - 1}"></a>
            <a th:if="${totalPages > 1}" th:href="@{/userList(currentPage=${totalPages})}" 
               th:class="${currentPage == totalPages} ? 'active' : ''" 
               th:text="${totalPages}"></a>

            <a th:if="${currentPage < totalPages}" th:href="@{/userList(currentPage=${currentPage + 1})}">
                <i class="fas fa-angle-right"></i>
            </a>
            <a th:if="${currentPage < totalPages}" th:href="@{/userList(currentPage=${totalPages})}">
                <i class="fas fa-angle-double-right"></i>
            </a>
        </div>

        <div class="page-info">
            <span th:text="'第 ' + ${currentPage} + ' 页'"></span>
            <span th:text="'共 ' + ${totalPages} + ' 页'"></span>
        </div>
    </div>

    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.1.3/js/bootstrap.bundle.min.js"></script>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // 删除确认
            const deleteButtons = document.querySelectorAll('.btn-delete');
            deleteButtons.forEach(button => {
                button.addEventListener('click', function(e) {
                    if (!confirm('确定要删除这个用户吗？')) {
                        e.preventDefault();
                    }
                });
            });
        });
    </script>
</body>
</html>